package com.gxuwz.eschool;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gxuwz.eschool.fragment.BookkingFragment;
import com.gxuwz.eschool.fragment.StatisticsFragment;
//易记账底部导航相关
public class BookkingActivity extends AppCompatActivity {

    private TextView tv_bookking;
    private TextView tv_statistics;
    private FragmentTransaction fragmentTransaction;
    private BookkingFragment bookkingFragment;
    private StatisticsFragment statisticsFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bookking);
        tv_bookking = findViewById(R.id.tv_bookking);
        tv_statistics = findViewById(R.id.tv_statistics);


        tv_bookking.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(bookkingFragment,tv_bookking);
            }
        });
        tv_statistics.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setFragment(statisticsFragment,tv_statistics);
            }
        });
        // 创建Fragment
        bookkingFragment = new BookkingFragment();
        statisticsFragment = new StatisticsFragment();
        setFragment(bookkingFragment,tv_bookking);


    }

    private void setFragment(Fragment fragment, TextView selected) {
        fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.layout_container, fragment);
        fragmentTransaction.commit();
        updateTextView(selected);
    }
    private void updateTextView(TextView selected) {
        int defaultColor = Color.GRAY; // 默认颜色
        int selectedTextColor = 0xff4fd458; // 选中文本颜色
        int defaultDrawable1 = R.drawable.icon_bookking_no; // 默认图标资源
        int selectedDrawable1 = R.drawable.icon_bookking; // 选中图标资源
        int defaultDrawable2 = R.drawable.icon_satistics_no; // 默认图标资源
        int selectedDrawable2 = R.drawable.icon_satistics; // 选中图标资源

        // 根据selected决定哪个TextView变
        if (selected == tv_bookking) {
            tv_bookking.setTextColor(selectedTextColor);
            tv_bookking.setCompoundDrawablesWithIntrinsicBounds(0, selectedDrawable1, 0, 0);
            tv_statistics.setTextColor(defaultColor);
            tv_statistics.setCompoundDrawablesWithIntrinsicBounds(0,defaultDrawable2,0,0);
        } else if (selected == tv_statistics) {
            tv_statistics.setTextColor(selectedTextColor);
            tv_statistics.setCompoundDrawablesWithIntrinsicBounds(0,selectedDrawable2,0,0);
            tv_bookking.setTextColor(defaultColor);
            tv_bookking.setCompoundDrawablesWithIntrinsicBounds(0, defaultDrawable1, 0, 0);

        }

    }

}